/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Mds_DataServe",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using DGZImp.MdsProject.DomainModels;
using DGZImp.MdsProject.IServices;
using DGZImp.Core.Utilities.Response;
using DGZImp.MdsProject.Devices.Models;
using DGZImp.Core.Extensions;

namespace DGZImp.MdsProject.Controllers
{
    public partial class Mds_DataServeController
    {
        private readonly IMds_DataServeService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Mds_DataServeController(
            IMds_DataServeService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        public override ApiResponse<object> GetPageData(PageDataOptions options)
        {
            var res = base.GetPageData(options);
            var data = (PageGridData<Mds_DataServe>)res.Data;
            foreach (var item in data.rows)
            {
                if (item.ServeType > 0)
                    item.ServeTypeTxt = ((ServeTypeEmun)item.ServeType).GetDescription();
            }
            return res;
        }

        [HttpPost("ReloadServe")]
        public async Task<ApiResponse<string>> ReloadServe([FromQuery] long? id)
        {
            await _service.ReloadServe(id);
            return ApiRes.Success("");
        }
    }
}
